local hx__diwangshi = fk.CreateSkill {
  name = "hx__diwangshi",
  tags = { Skill.Compulsory , Skill.Switch },
}

hx__diwangshi:addEffect(fk.TurnStart, {
  anim_type = "switch",
  priority = 2,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__diwangshi.name)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYin then
      room:setPlayerMark(player, "@@hx__diwangshi-ze", 0)
      room:addPlayerMark(player, "@@hx__diwangshi-ping")
    else
      room:setPlayerMark(player, "@@hx__diwangshi-ping", 0)
      room:addPlayerMark(player, "@@hx__diwangshi-ze")
    end
    player:setSkillUseHistory(hx__diwangshi.name, 0, Player.HistoryGame)
  end,
})

hx__diwangshi:addEffect("prohibit", {
  name = "hx__diwangshi",
  anim_type = "defensive",
  is_delay_effect = true,
  is_prohibited = function(self, from, to, card)
    return to:hasSkill(hx__diwangshi.name) and card and card.sub_type == Card.SubtypeDelayedTrick and 
     to:getMark("@@hx__diwangshi-ze") > 0
  end,
})

hx__diwangshi:addEffect(fk.DrawNCards, {
  anim_type = "drawcard",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    if not player:hasSkill(hx__diwangshi.name) or player ~= target then return false end
    if player:getMark("@@hx__diwangshi-ze") > 0 then
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    data.n = data.n + 3
  end,
})

hx__diwangshi:addEffect(fk.Damage, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__diwangshi.name) and player:getMark("@@hx__diwangshi-ze") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@@hx__diwangshi")
  end,
})

hx__diwangshi:addEffect(fk.Damaged, {
  anim_type = "defensive",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__diwangshi.name) and player:getMark("@@hx__diwangshi-ze") == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@@hx__diwangshi")
  end,
})

hx__diwangshi:addEffect(fk.TurnStart, {
  anim_type = "defensive",
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__diwangshi.name) and player:getMark("@@hx__diwangshi") > 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, self.name)
    room:setPlayerProperty(player, "hp", player.maxHp)
    room:setPlayerMark(player, "@@hx__diwangshi", 0)
  end,
})



return hx__diwangshi